<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        body {
            background-color: rgb(241, 242, 243);
        }

        .el-header {
            background-color: white;
        }

        .center {
            width: 1200px;
            margin: 0 auto
        }

        footer h3 {
            color: white;
        }

        #footer_center p {
            margin: 0;
        }


    </style>
</head>
<body>
<div id="app">
    <el-container>
        <my-header></my-header>
        <el-main class="center" style="margin-top: 30px">
            <el-row gutter="10">
                <el-col span="4">
                    <el-card style="height: 1000px">
                        <el-menu @select="handleSelect" style="border: 0" default-active="2" active-text-color="orange">
                            <el-menu-item index="1">
                                个人信息
                            </el-menu-item>
                            <el-menu-item index="2">
                                稿件管理
                            </el-menu-item>
                        </el-menu>
                    </el-card>
                </el-col>
                <el-col span="20">
                    <el-card>
                        <el-tabs v-model="type" type="border-card">
                            <el-tab-pane name="1" label="食谱">
                                <el-button type="primary" @click="location.href='postArticle.html?type=1'">发布食谱
                                </el-button>
                                <el-table :data="recipeArr" border>
                                    <el-table-column label="标题" align="center"
                                                     width="150px" prop="title"></el-table-column>
                                    <el-table-column width="60px" label="封面">
                                        <template slot-scope="scope">
                                            <img :src="scope.row.imgUrl" width="50px">
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="摘要" width="300px"
                                                     prop="brief" align="center"></el-table-column>
                                    <el-table-column label="类型" prop="categoryName"
                                                     align="center"></el-table-column>
                                    <el-table-column label="浏览量" prop="viewCount"
                                                     align="center"></el-table-column>
                                    <el-table-column label="回复量" prop="commentCount"
                                                     align="center"></el-table-column>
                                    <el-table-column label="创建时间" prop="createTime"
                                                     align="center"></el-table-column>

                                    <el-table-column label="操作" width="200px" align="center" fixed="right">
                                        <template slot-scope="scope">
                                            <el-button size="mini" type="success"
                                                       @click="handleEdit(scope.$index,scope.row)">编辑
                                            </el-button>
                                            <el-button size="mini" type="danger"
                                                       @click="handleDelete(scope.$index,scope.row)">删除
                                            </el-button>
                                        </template>
                                    </el-table-column>

                                </el-table>
                            </el-tab-pane>
                            <el-tab-pane name="2" label="视频">
                                <el-button type="primary" @click="location.href='postArticle.html?type=2'">发布视频
                                </el-button>
                                <el-table :data="videoArr" border>
                                    <el-table-column label="标题" align="center"
                                                     width="150px" prop="title"></el-table-column>
                                    <el-table-column width="60px" label="封面">
                                        <template slot-scope="scope">
                                            <img :src="scope.row.imgUrl" width="50px">
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="类型" prop="categoryName"
                                                     align="center"></el-table-column>
                                    <el-table-column label="浏览量" prop="viewCount"
                                                     align="center"></el-table-column>
                                    <el-table-column label="回复量" prop="commentCount"
                                                     align="center"></el-table-column>
                                    <el-table-column label="创建时间" prop="createTime"
                                                     align="center"></el-table-column>

                                    <el-table-column label="操作" width="200px" align="center" fixed="right">
                                        <template slot-scope="scope">
                                            <el-button size="mini" type="success"
                                                       @click="handleEdit(scope.$index,scope.row)">编辑
                                            </el-button>
                                            <el-button size="mini" type="danger"
                                                       @click="handleDelete(scope.$index,scope.row)">删除
                                            </el-button>
                                        </template>
                                    </el-table-column>

                                </el-table>
                            </el-tab-pane>
                            <el-tab-pane name="3" label="资讯">
                                <el-button type="primary" @click="location.href='postArticle.html?type=3'">发布资讯
                                </el-button>
                                <el-table :data="infoArr" border>
                                    <el-table-column label="标题" align="center"
                                                     width="150px" prop="title"></el-table-column>
                                    <el-table-column width="60px" label="封面">
                                        <template slot-scope="scope">
                                            <img :src="scope.row.imgUrl" width="50px">
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="摘要" width="300px"
                                                     prop="brief" align="center"></el-table-column>
                                    <el-table-column label="类型" prop="categoryName"
                                                     align="center"></el-table-column>
                                    <el-table-column label="浏览量" prop="viewCount"
                                                     align="center"></el-table-column>
                                    <el-table-column label="回复量" prop="commentCount"
                                                     align="center"></el-table-column>
                                    <el-table-column label="创建时间" prop="createTime"
                                                     align="center"></el-table-column>

                                    <el-table-column label="操作" width="200px" align="center" fixed="right">
                                        <template slot-scope="scope">
                                            <el-button size="mini" type="success"
                                                       @click="handleEdit(scope.$index,scope.row)">编辑
                                            </el-button>
                                            <el-button size="mini" type="danger"
                                                       @click="handleDelete(scope.$index,scope.row)">删除
                                            </el-button>
                                        </template>
                                    </el-table-column>

                                </el-table>
                            </el-tab-pane>
                        </el-tabs>


                    </el-card>
                </el-col>
            </el-row>

        </el-main>
        <el-footer style="background-color: #2f3234;
        height: 280px;padding: 50px 0">
            <div class="center" style="color: #666;text-align: center">
                <el-row gutter="20">
                    <el-col span="8">
                        <img src="imgs/icon.png">
                        <p>教程灵感就看烘焙坊</p>
                        <p>烘焙行业网络社区平台</p>
                        <p>全国百城上千个职位等你来</p>
                    </el-col>
                    <el-col span="8">
                        <el-row id="footer_center">
                            <el-col span="8">
                                <h3>关于我们</h3>
                                <p>关于我们</p>
                                <p>烘焙学院</p>
                                <p>烘焙食谱</p>
                                <p>分类信息</p>
                                <p>求职招聘</p>
                                <p>社区交流</p>
                            </el-col>
                            <el-col span="8">
                                <h3>服务与支持</h3>
                                <p>联系我们</p>
                                <p>广告投放</p>
                                <p>用户协议</p>
                                <p>友情链接</p>
                                <p>在线反馈</p>
                                <p>我发投稿</p>
                            </el-col>
                            <el-col span="8">
                                <h3>底部导航</h3>
                                <p>Archiver</p>
                                <p>手机版</p>
                                <p>小黑屋</p>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col span="8">
                        <div style="font-size: 60px;">
                            <span style="color: orange">烘焙</span>坊
                        </div>
                        <p>烘焙行业网络社区平台</p>
                    </el-col>
                </el-row>
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入Axios-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="js/my-header.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                recipeArr: [],
                videoArr: [],
                infoArr: [],
                type:"1"
            }
        },
        methods: {
            handleEdit(i, c) {
                location.href = "/postArticle.html?type=" + c.type + "&id=" + c.id;
            },
            handleDelete(i, c) {
                if (confirm("您确认删除此内容吗?")) {
                    axios.post("/v1/contents/" + c.id + "/delete").then(function (response) {
                        if (response.data.code == 1) {
                            v.$message.success("删除完成!");
                            if (c.type == 1) {
                                v.recipeArr.splice(i, 1);
                            } else if (c.type == 2) {
                                v.videoArr.splice(i, 1);
                            } else {
                                v.infoArr.splice(i, 1);
                            }
                        }
                    })
                }
            },
            handleSelect(key, keyPath) {
                if (key == 1) {
                    location.href = "personal.html";
                }
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            }

        },
        created: function () {
            if (location.search.includes("type")) {
                this.type = new URLSearchParams(location.search).get("type")
            }
            //请求所有食谱
            axios.get("/v1/contents/1/management").then(function (response) {
                if (response.data.code == 1) {
                    v.recipeArr = response.data.data;
                }
            })
            //请求所有视频
            axios.get("/v1/contents/2/management").then(function (response) {
                if (response.data.code == 1) {
                    v.videoArr = response.data.data;
                }
            })
            //请求所有资讯
            axios.get("/v1/contents/3/management").then(function (response) {
                if (response.data.code == 1) {
                    v.infoArr = response.data.data;
                }
            })
        }
    })
</script>
</html>